{extend name="$base" /}
{block name="main"}
<div class="set-style">

	<div class="set-item">
		<dl>
			<dt>会员注册送银币：</dt>
			<dd>
				<p>
					<input id="reg_member_self_point" type="number" min="0" value="{$reward_rule_info.reg_member_self_point}" onkeyup="value=value.replace(/[^\d+]/g,'')" class="input-common harf">
					<em class="unit">分</em>
				</p>
			</dd>
		</dl>
		<dl>
			<dt></dt>
			<dd>
				<p>
					<input id="register_open" type="checkbox" onchange="setMemberActionConfig();" class="checkbox" {if condition="$member_action_config['register_integral'] eq 1"}checked="checked"{/if}/>
				</p>
				<p class="hint">是否启用会员注册送银币</p>
			</dd>
		</dl>
		<dl>
			<dt>会员注册送优惠券：</dt>
			<dd>
				<select class="row-no-radius select-common" id="reg_coupon">
					<option value="">请选择优惠券种类</option>
					{foreach name="$coupon_list" item="v"}
						{if condition="$v['coupon_type_id'] == $reward_rule_info['reg_coupon']"}
						<option value="{$v.coupon_type_id}" selected="selected">{$v.coupon_name}</option>
						{else/}
						<option value="{$v.coupon_type_id}">{$v.coupon_name}</option>
						{/if}
					{/foreach}
				</select>
			</dd>
		</dl>
		<dl>
			<dt></dt>
			<dd>
				<p>
					<input id="reg_coupon_open" type="checkbox" onchange="setMemberActionConfig();" class="checkbox" {if condition="$member_action_config['register_coupon'] eq 1"}checked="checked"{/if}/>
				</p>
				<p class="hint">是否启用会员注册送优惠券</p>
			</dd>
		</dl>
	</div>
	<dl>
		<dt></dt>
		<dd>
			<button class="btn-common btn-big" onclick="save();" style="margin:20px 0 20px 205px;">保存</button>
		</dd>
	</dl>
</div>
<script>
function setMemberActionConfig(){
	if($("#register_open").prop("checked")){
		var register = 1;
	}else{
		var register = 0;
	}
	if($("#reg_coupon_open").prop("checked")){
		var reg_coupon_open = 1;
	}else{
		var reg_coupon_open = 0;
	}
	$.ajax({
		type : 'post',
		url : "{:__URL('__URL__/NsMemberRegister/ADMIN_MODULE/MemberRegister/setMemberActionConfig')}",
		data : { 'register':register, 'reg_coupon':reg_coupon_open, },
		success : function(data){
			//alert(JSON.stringify(data));
		}
	})
}

function save(){
	var reg_member_self_point = $("#reg_member_self_point").val();
	var reg_coupon = $("#reg_coupon").val();
	if($("#reg_coupon_open").prop("checked")){
		if(reg_coupon == ""){
			showMessage("error","请选择优惠券种类");
			return;
		}
	}
	$.ajax({
		type : 'post',
		url : "{:__URL('__URL__/NsMemberRegister/ADMIN_MODULE/MemberRegister/index')}",
		data : { "reg_member_self_point" : reg_member_self_point, 'reg_coupon':reg_coupon },
		success : function(data){
			if(data['code'] >=0){
				showMessage("success", "设置成功！", "{:__URL('__URL__/NsMemberRegister/ADMIN_MODULE/MemberRegister/index')}");
			}else{
				showMessage("error", "设置失败");
			}
		}
	})
}
</script>
{/block}
